/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.edu.fatec.ads.classes;

import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 *
 * @author Roberta Ferreira
 */
@Entity
@DiscriminatorValue("2")
public class Andar extends Local {

    private Predio predio;
    private List<Sala> salas;

    public Andar() {
        super(2);
    }

    public Andar(int codigo){
        super(codigo, 2);
    }

    /**
     * @return the predio
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @Fetch(FetchMode.SELECT)
    @JoinColumns(value={@JoinColumn(name = "cd_local_referencia", nullable = false),
                        @JoinColumn(name = "cd_tp_referencia", nullable = false)})
    public Predio getPredio() {
        return predio;
    }

    /**
     * @param predio the predio to set
     */
    public void setPredio(Predio predio) {
        this.predio = predio;
    }

    /**
     *
     * @return
     */
    @OneToMany(mappedBy="andar", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    @Fetch(FetchMode.SELECT)
    public List<Sala> getSalas() {
        return salas;
    }

    /**
     *
     * @param salas
     */
    public void setSalas(List<Sala> salas) {
        this.salas = salas;
    }

    @Override
    public String toString() {
        return "Andar[codigo=" + this.getCodigo()
                + ", nome=" + this.getNome()
                + ", numero=" + this.getNumero()
                + ", predio=" + this.getPredio().getCodigo() + "]";
    }
}
